/**
 * Created by Administrator on 2019/5/21/021.
 */
import CZML_GENERALTOOLS_CLASS from "./../main/CZML_GENERALTOOLS_CLASS.js"

class CZML_DeleteObjectByID {
    constructor(viewer, id) {
        this._viewer = viewer
        this.id = id
        this.CZML_DeleteObjectByID()
    }

    CZML_DeleteObjectByID() {
        const viewer = this._viewer
        const id = this.id

        // for (var j = 0; j < viewer.scene.primitives.length; j++) {
        //    if (viewer.scene.primitives._primitives[j].hasOwnProperty('id')) {
        //        if (viewer.scene.primitives._primitives[j].id.split("+")[0] == id) {
        //            viewer.scene.primitives.removeAndDestroy(viewer.scene.primitives._primitives[j]);
        //        }
        //    }
        // }
        // var deletelistener = viewer.scene.preUpdate._listeners.filter(function (item) {
        //    return item.name == 'listen'
        // })[0];
        // viewer.scene.preUpdate.removeEventListener(deletelistener, 'listen');
        const MapNodes = CZML_GENERALTOOLS_CLASS.CzmlList.map(function (node) {
            return node.data().id.includes(id)
        })
        if (CZML_GENERALTOOLS_CLASS.AngleDisplayEvent.has(id + "angle_event")) {
            CZML_GENERALTOOLS_CLASS.AngleDisplayEvent.delete(id + "angle_event")
            if (CZML_GENERALTOOLS_CLASS.AngleDisplayEvent.size === 0) {
                viewer.scene.preRender.removeEventListener(CZML_GENERALTOOLS_CLASS.AngleDisplayEvent)
            }
        }
        for (let i = 0; i < MapNodes.length; i++) {
            CZML_GENERALTOOLS_CLASS.CzmlList.remove(MapNodes[i])
        }
        if (MapNodes.length > 0) {
            CZML_GENERALTOOLS_CLASS.Upper(this._viewer)
        }
    }
}
export default CZML_DeleteObjectByID
